/*
 *      Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *
 *  Redistributions of source code must retain the above copyright notice,
 *  this list of conditions and the following disclaimer.
 *  Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the distribution.
 *  Neither the name of the dreamlu.net developer nor the names of its
 *  contributors may be used to endorse or promote products derived from
 *  this software without specific prior written permission.
 *  Author: Chill 庄骞 (smallchill@163.com)
 */
package cn.zkrt.iotms.module.data.controller;


import cn.zkrt.iotms.comm.R;
import cn.zkrt.iotms.module.data.dto.AttributeData;
import cn.zkrt.iotms.module.data.dto.InfluxDto;
import cn.zkrt.iotms.module.data.service.InfluxdbService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * 设备表 控制器
 *
 * @author Blade
 * @since 2022-11-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/data")
@Api(tags = "设备数据")
public class DeviceDataController {


    @Autowired
    private InfluxdbService influxdbService;


    @PostMapping("/getHistories")
    @ApiOperation("获取`设备数据`历史记录")
    @ResponseBody
    public R<Map<String, List<AttributeData>>> getHistories(InfluxDto influxDto){

        return R.data(influxdbService.getHistories(influxDto));
    }

    @PostMapping("/historiesPage")
    @ApiOperation("分页获取`设备数据`历史记录")
    @ResponseBody
    public R<Page<AttributeData>> historiesPage(Page<AttributeData> page, InfluxDto influxDto) {

        return R.data(influxdbService.historiesPage(page,influxDto));
    }

}
